<?php
/**
 * 人脸登陆唯一凭证
 * Created by PhpStorm.
 * User: liyy
 * Date: 2017/7/27 0027
 * Time: 下午 3:39
 */

namespace app\api\model;

use think\Db;
use think\Model;
class Goods extends Model{

    /**
     * 获取一级分类
     */
    public function OneCatList(){
        $where['parent_id'] = 0;
        $where['is_show'] = 1;
        $where['level'] = 1;
        $catList = Db::name('goods_category')
                    ->field('name,id,image')
                    ->where($where)
                    ->order('sort_order desc')
                    ->limit(9)
                    ->select();
        return $catList;

    }

    /**
     * 获取首页轮播图图片
     */
    public function Adselect($index,$limit){
        if ($index){
            $where['app_show'] = $index;
        }else{
            $where['app_show'] = 1;
        }
        if (empty($limit)){
            $limit = 3;
        }
        $where['enabled'] = 1;
        $adList = Db::name('ad')
            ->field('ad_link,ad_id,ad_name,ad_code')
            ->where($where)
            ->order('orderby desc')
            ->limit($limit)
            ->select();
        return $adList;

    }

    /**
     * 判断是否存在该商品
     */
    public function goodsFind($goods_id){
        if ($goods_id <= 0){
            return false;
        }

        $where['is_on_sale'] = 1;
        $where['goods_id'] = $goods_id;
        $data = Db::name('Goods')->field('goods_id')->where($where)->find();
        if ($data){
            return $data;
        }else{
            return false;
        }
    }


}